<?php
defined('_JEXEC') or die;

JHtml::_('behavior.keepalive');
$user = JFactory::getUser();
extract($this->data->information);//all keys become variables

function selectpair($min, $max, $dat){
	$i=$min;
	while( $i<=$max )
		{echo '<option value="' ,$i, '"' ,($dat==$i ? " selected" : ''), '>' ,str_pad($i, 2, '0', STR_PAD_LEFT),'</option>';$i++;}
}
$meal1=explode('-', $meal1);
$meal2=explode('-', $meal2);
$meal3=explode('-', $meal3);
$meal4=explode('-', $meal4);
$meal5=explode('-', $meal5);

require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
if ( $detect->isMobile() ) {
    include('edit2_mobile.php');
    return;
}
?>
<style type="text/css">
	.w115{width: 115px}
	.ml30{margin-left: 30px}
</style>
<div class="wrapper">
	<div class="content" id="dietaryHabits-page">
		<div class="col-wrapper clearfix">
			<div class="info">
				<ul class="breadcrumb mb20">
					<li><a href="index.php?option=com_users&view=profile&layout=edit">Personlige oplysninger</a></li>
					<li class="active"><a>Kostvaner/ønsker</a></li>
					<li><a href="index.php?option=com_users&view=profile&layout=edit3">Motionsvaner/ønsker</a></li>
				</ul>
				<form name="reg_form2" id="member-edit" action="index.php" method="post" class="form-validate" enctype="multipart/form-data">
					<h1 class="hd">Kostvaner/ønsker</h1>
					<div class="colum bor mr27 fl m-h">
						<div class="col-wra">
							<div>Nuværende spisevaner:</div>
							<div>
								<label>Spiser du morgenmad regelmæssigt?</label>
							</div>
<?php
	$tmp='';
	$tmp1=" checked";
	$tmp2=' class="hide"';
	if($breakfast){list($tmp,$tmp1) = array($tmp1,$tmp);$tmp2='';}
	?>
		<div class="fr">
			<label class="uper">Ja/Nej</label>
			<input type="radio" class="ra" name="r1" value="1"<?php echo $tmp?>>
			<input type="radio" class="ra" name="r1" value=""<?php echo $tmp1?>>
		</div>
		<div id="opt1"<?php echo $tmp2?>>
			<label class="fl ita w150">Hvis ja, hvad spiser du?</label>
			<input class="w86" name="jform[breakfast]" value="<?php echo $breakfast?>">
		</div>
						</div>

						<div class="col-wra">
							<div style="width: 210px;">
								<label>Drikker du sodavand?</label>
							</div>
<?php
	$tmp='';
	$tmp1=" checked";
	$tmp2=' class="hide"';
	if($soda){list($tmp,$tmp1) = array($tmp1,$tmp);$tmp2='';}
	?>
		<div class="fr">
			<label class="uper">Ja/Nej</label>
			<input class="ra" type="radio" name="r2" value="1"<?php echo $tmp?>>
			<input class="ra" type="radio" name="r2" value=""<?php echo $tmp1?>>
		</div>
		<div id="opt2"<?php echo $tmp2?>>
			<label class="fl ita w150">Hvis ja, hvor meget ca. pr. dag?</label>
			<input class="w86" name="jform[soda]" value="<?php echo $soda?>">
		</div>
						</div>

						<div class="col-wra">
							<div style="width: 210px;">
								<label>Mener du, at du spiser nogenlunde <br> sundt</label>
							</div>
<?php
	$tmp='';
	$tmp1=" checked";
	$tmp2=' class="hide"';
	if($eatwell){list($tmp,$tmp1) = array($tmp1,$tmp);$tmp2='';}
	?>
		<div class="fr">
			<label class="uper">Ja/Nej</label>
			<input class="ra" type="radio" name="r3" value="1"<?php echo $tmp?>>
			<input class="ra" type="radio" name="r3" value=""<?php echo $tmp1?>>
		</div>
		<div id="opt3"<?php echo $tmp2?>>
			<label class="fl ita w150">Hvor stor en procentdel af det du indtager, mener du er sundt?</label>
			&nbsp;<input name="jform[eatwell]" style="width:22px;margin-left: 60px" value="<?php echo $eatwell?>">&nbsp;%
		</div>
						</div>

						<div class="col-wra">
							<div>
								<label>Har du nogen form for spiseforstyrrelser</label><?php //rối loạn ăn uống, kén ăn?>
							</div>
<?php
	$tmp='';
	$tmp1=" checked";
	$tmp2=' class="hide"';
	if($roiloan!=""){list($tmp,$tmp1) = array($tmp1,$tmp);$tmp2='';}
	?>
		<div class="fr">
			<label class="uper">Ja/Nej</label>
			<input class="ra" type="radio" name="r4" value="1"<?php echo $tmp?>>
			<input class="ra" type="radio" name="r4" value=""<?php echo $tmp1?>>
		</div>
		<div class="clear"></div>
<?php
	if($roiloan==""){$tmp='';$tmp1="";}
	elseif($roiloan==1){$tmp1='';$tmp=" checked";}
	elseif($roiloan===0){$tmp='';$tmp1=" checked";}
	?>
		<div id="opt4"<?php echo $tmp2?> style="float: none">
			<div>
				<label>Hvis ja, har du fået eller får du hjælp?</label><?php //đã có ai giúp chưa?>
			</div>
			<div class="clear"></div>
			<div class="fr">
				<label class="uper">Ja/Nej</label>
				<input class="ra" type="radio" name="jform[roiloan]" value="1"<?php echo $tmp?>>
				<input class="ra" type="radio" name="jform[roiloan]" value="0"<?php echo $tmp1?>>
			</div>
		</div>
						</div>

					</div>

					<div class="colum bor mr27 fl m-h">
						<div class="col-wra">
							<div>Mulige kostvaner:</div>
							<div>Hvornår på dagen har du mulighed for at spise</div>
							<div class="mb0">
								<div class="fl w100 mt25">Måltid 1:</div>
								<div class="fl">
									<label>Fra kl.</label>
									<select name="jform[meal1a]" class="w76">
<?php
selectpair(2,10,$meal1[0]);
?>
									</select>
								</div>
								<div class="fl ml7">
									<label>Til kl.</label>
									<select name="jform[meal1b]" class="w76">
<?php
selectpair(3,11,$meal1[1]);
?>
									</select>
								</div>
							</div>

							<div class="mb0">
								<div class="fl w100 mt8">Måltid 2:</div>
								<div class="fl">
									<select name="jform[meal2a]" class="w76">
<?php
selectpair(9,17,$meal2[0]);
?>
									</select>
								</div>
								<div class="fl ml7">
									<select name="jform[meal2b]" class="w76">
<?php
selectpair(10,18,$meal2[1]);
?>
									</select>
								</div>
							</div>

							<div class="mb0">
								<div class="fl w100 mt8">Måltid 3:</div>
								<div class="fl">
									<select name="jform[meal3a]" class="w76">
<?php
selectpair(11,21,$meal3[0]);
?>
									</select>
								</div>
								<div class="fl ml7">
									<select name="jform[meal3b]" class="w76">
<?php
selectpair(12,22,$meal3[1]);
?>
									</select>
								</div>
							</div>

							<div class="mb0">
								<div class="fl w100 mt8">Måltid 4:</div>
								<div class="fl">
									<select name="jform[meal4a]" class="w76">
<?php
selectpair(13,22,$meal4[0]);
?>
									</select>
								</div>
								<div class="fl ml7">
									<select name="jform[meal4b]" class="w76">
<?php
selectpair(14,23,$meal4[1]);
?>
									</select>
								</div>
							</div>

							<div class="mb0">
								<div class="fl w100 mt8">Måltid 5:</div>
								<div class="fl">
									<select name="jform[meal5a]" class="w76">
<?php
selectpair(14,22,$meal5[0]);
?>
									</select>
								</div>
								<div class="fl ml7">
									<select name="jform[meal5b]" class="w76">
<?php
selectpair(15,23,$meal5[1]);
?>
									</select>
								</div>
							</div>
						</div>

						<div class="col-wra">
							<p class="mt5">Er det vigtigt, at den kost du indtager, er varierende og smagsfuld?</p>
							<div>
								<input class="ra" type="radio" name="jform[diversity]" value="-1"> Ikke vigtigt<br class="mb10">
								<input class="ra" type="radio" name="jform[diversity]" value="1"> Meget vigtigt<br class="mb10">
								<input class="ra" type="radio" name="jform[diversity]" value="0"> Ingen af delene
							</div>
						</div>
					</div>

					<div class="colum bor fr m-h">
						<div>Mulige kostvaner:</div>
						<div>Hvor meget tid vil du ca. bruge<br>på at lave mad pr. dag?</div>
						<div class="fr">
							<select class="w76" name="jform[cooktime]" style="margin-left: 10px">
								<option value="0">0 min</option>
								<option value="30">30 min</option>
								<option value="45">45 min</option>
								<option value="60">60 min</option>
								<option value="90">90 min</option>
								<option value="120">2 timer</option>
								<option value="180">+3 timer</option>
							</select>
						</div>
						<div class="mt8">Hvilke fødevarer kan du lide?</div>
						<div class="clear"></div>
<?php
$fav=explode("-",$fav);
$fav[0]= explode(",", $fav[0]);
$fav[1]=explode(",", $fav[1], count($fav[0]));
$fav=array_combine($fav[0], $fav[1]);
?>
						<div class="w115 fl">
							<label class="w73 fl">Kylling</label>
							<input class="ck" type="checkbox" name="jform[fav][0]" value="Kylling"<?php echo $fav[0] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl ml30">
							<label class="w73 fl">Rodfrugter</label>
							<input class="ck" type="checkbox" name="jform[fav][1]" value="Rodfrugter"<?php echo $fav[1] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl">
							<label class="w73 fl">Oksekød</label>
							<input class="ck" type="checkbox" name="jform[fav][2]" value="Oksekød"<?php echo $fav[2] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl ml30">
							<label class="w73 fl">Chili</label>
							<input class="ck" type="checkbox" name="jform[fav][3]" value="Chili"<?php echo $fav[3] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl">
							<label class="w73 fl">Svinekød</label>
							<input class="ck" type="checkbox" name="jform[fav][4]" value="Svinekød"<?php echo $fav[4] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl ml30">
							<label class="w73 fl">Proteinpulver</label>
							<input class="ck" type="checkbox" name="jform[fav][5]" value="Proteinpulver"<?php echo $fav[5] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl">
							<label class="w73 fl">Brune ris</label>
							<input class="ck" type="checkbox" name="jform[fav][6]" value="Brune ris"<?php echo $fav[6] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl ml30">
							<label class="w73 fl">Æg</label>
							<input class="ck" type="checkbox" name="jform[fav][7]" value="Æg"<?php echo $fav[7] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl">
							<label class="w73 fl">Grønne bønner</label>
							<input class="ck" type="checkbox" name="jform[fav][8]" value="Grønne bønner"<?php echo $fav[8] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl ml30">
							<label class="w73 fl">Fisk</label>
							<input class="ck" type="checkbox" name="jform[fav][9]" value="Fisk"<?php echo $fav[9] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl">
							<label class="w73 fl">Ost</label>
							<input class="ck" type="checkbox" name="jform[fav][10]" value="Ost"<?php echo $fav[10] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl ml30">
							<label class="w73 fl">Nødder</label>
							<input class="ck" type="checkbox" name="jform[fav][11]" value="Nødder"<?php echo $fav[11] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl">
							<label class="w73 fl">Hakket kød<br>(svin/kalvekød/<br>okse)</label>
							<input class="ck" type="checkbox" name="jform[fav][12]" value="Hakket kød (svin/kalvekød/okse)"<?php echo $fav[12] ? ' checked=""':""?>>
						</div>
						<div class="w115 fl ml30">
							<label class="w73 fl">Mælkeprodukter<br>(ymer, fromage<br>frais etc.)</label>
							<input class="ck" type="checkbox" name="jform[fav][13]" value="Mælkeprodukter (ymer, fromage frais etc.)"<?php echo $fav[13] ? ' checked=""':""?>>
						</div>
						<div>Er du allergisk overfor nogle<br>fødevarer?</div>
<?php if($allergy){?>
	<div class="fr">
		<label class="uper">Ja/Nej</label>
		<input class="ra" type="radio" name="r5" value="1" checked>
		<input class="ra" type="radio" name="r5" value="">
	</div>
	<div class="clear"></div>
	<div id="opt5" style="float: none">
		<label class="fl ita w100">Hvis ja, hvad?</label>
		<input class="w86" name="jform[allergy]" value="<?php echo $allergy?>">
	</div>
<?php }else{?>

						<div class="fr">
							<label class="uper">Ja/Nej</label>
							<input class="ra" type="radio" name="r5" value="1">
							<input class="ra" type="radio" name="r5" value="" checked>
						</div>
						<div class="clear"></div>
						<div id="opt5" class="hide" style="float: none">
							<label class="fl ita w100">Hvis ja, hvad?</label>
							<input class="w86" name="jform[allergy]">
						</div>
<?php }?>
					</div>

					<div class="clear"></div>
					<a class="fl bntPrevious" href="<?php echo JRoute::_('index.php?option=com_users&view=profile&layout=edit&Itemid=117')?>">Forrige</a>
					<a class="fr bntNext" onclick="$('#member-edit').submit()">Næste</a>
					<input type="hidden" name="option" value="com_users" />
					<input type="hidden" name="task" value="profile.edit" />
					<input type="hidden" name="user_id" value=<?php echo $user->id?> />
					<?php echo JHtml::_('form.token');?>
				</form>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
var f2=document.reg_form2;
	$(document).ready(function(){
		$("input[name=r1]").change(function() {
			$("#opt1").toggle();
			if(!$(this).val())
				f2.elements["jform[breakfast]"].value="";
		});

		$("input[name=r2]").change(function() {
			$("#opt2").toggle();
			if(!$(this).val())
				f2.elements["jform[soda]"].value="";
		});

		$("input[name=r3]").change(function() {
			$("#opt3").toggle();
			if(!$(this).val())
				f2.elements["jform[eatwell]"].value="";
		});

		$("input[name=r4]").change(function(){
			$("#opt4").toggle();
			if(!$(this).val()){
				f2.elements["jform[roiloan]"][0].checked=false;
				f2.elements["jform[roiloan]"][1].checked=false;
			}
		});

		$("input[name=r5 ]").change(function() {
			$("#opt5").toggle();
			if(!$(this).val())
				f2.elements["jform[allergy]"].value="";
		});
	});
<?php
	echo 'f2.elements["jform[diversity]"].value=',$diversity,';';
	echo 'f2.elements["jform[cooktime]"].value=',$cooktime,';';
?>
</script>